/*
 * This file is part of ddesktop: remote desktop system for iPad 
 *
 * Copyright (C) 2010 Kazuhiro Satoh
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. if not, see <http://www.gnu.org/licenses/>.
 */

#import <Foundation/Foundation.h>
#import "constants.h"


#define NUM_BUFFER  8


enum PortStates{
	PORT_STATE_CLOSED = 0,
	PORT_STATE_OPENED,
	PORT_STATE_ERROR
};

typedef struct ImageBuf_tag {
	uint8_t *buf;
	int headerSize;
	int dataSize;
	int x;
	int y;
	int width;
	int height;
	float zoomScale;
} ImageBuf;


@interface DDClientPort : NSObject {
@private
	int _commandSocketFd;
	int _dataSocketFd;
	uint32_t _dataPort;
	int _dataListenSocketFd;
	CGSize _screenSize;
	CGRect _downloadFrame;
	ImageBuf _imageBuf[NUM_BUFFER];
	int _readyBufNum;
	int _downloadFrameCt;
	enum PortStates _state;
}


@property (nonatomic,readonly) ImageBuf* imageBufPt;
@property (nonatomic,readonly) CGSize screenSize;
@property (nonatomic,readonly) CGRect downloadFrame;
@property (nonatomic,readonly) int downloadFrameCt;
@property (nonatomic,readonly) enum PortStates state;


- (id)init;
- (void)connectToHost:(NSString*)hostname port:(int)port;
- (BOOL)close;
- (BOOL)startDownloading;
- (BOOL)stopDownloading;
- (BOOL)changeDownloadFrame:(CGRect)frame zoomScale:(float)zoomScale;
- (BOOL)downloadFrame:(CGRect)frame;  // for debug

- (BOOL)sendUIEvent:(enum DDUIEventType)eventType eventOwner:(enum DDUIEventOwner)eventOwner param1:(int)param1 param2:(int)param2;
- (BOOL)sendKeyinputs:(NSString*)str;
- (void)changeImageQuality:(int)quality;
- (void)changeImageResolution:(int)resolution;


@end
